package com.zhongshengnetwork.rightbe.dbservice;

import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.dbmodel.CommentdbModel;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

import java.util.List;

public class CommentdbService {

    //插入或者更新数据
    public static boolean saveOrUpdate(CommentdbModel model){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.saveOrUpdate(model);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //获取数据
    public static CommentdbModel getData(String sourceid){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            return db.findById(CommentdbModel.class,sourceid);
        } catch (DbException e) {
            e.printStackTrace();
            return null;
        }
    }

    //删除数据
    public static boolean deleteData(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.delete(CommentdbModel.class);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean deleteById(String id){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.deleteById(CommentdbModel.class,id);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

}
